package net.stratusprogramming.school.Game.Battle.GUI;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import net.stratusprogramming.school.Game.Framework.Scene.Actor;
import net.stratusprogramming.school.Game.Framework.Scene.Misc.ImageActor;
import net.stratusprogramming.school.Game.Framework.System.SaveMgr;

/**
 * The background of the battle screen
 * 
 * @author Patrick Lienau
 * @since 5/9/12
 * @version 0.1
 */
public class Background extends Actor {

	/** How fast the background will scroll */
	private final static float SPEED = 0.25f;
	
	/** Height of BG */
	private float height; 
	/** Overlapping background tiles that will be drawn */
	public ImageActor[] tiles;
	
	
	/**
	 * Creates/loads the background
	 */
	public Background() {
		try {
			// load tiles
			Image bgImg = new Image("res/images/battle/bg.jpg");
			height = bgImg.getHeight();
			tiles = new ImageActor[] {new ImageActor(bgImg), new ImageActor(bgImg)};	
			
			// initial position for tiles
			tiles[0].setX(0);
			tiles[0].setY(0);
			tiles[1].setX(0);
			tiles[1].setY(height);
		
		} catch (SlickException e) {}
	}
	
	@Override
	public void update(int delta) {
		// animate
		float dist = SPEED*delta;
		tiles[0].setY(tiles[0].getY()-dist);
		tiles[1].setY(tiles[1].getY()-dist);

		// offscreen?
		if(tiles[0].getY() < -height) {
			// reposition
			tiles[0].setY(tiles[1].getY()+height);
			
			// swap
			ImageActor temp = tiles[0];
			tiles[0] = tiles[1];
			tiles[1] = temp;
		}
	}

	@Override
	public void render(Graphics g) {
		// 1 then 0 so 0 is on top ;)
		tiles[1].render(g);
		tiles[0].render(g);
	}

	@Override
	public void save(SaveMgr saveMgr) {
		// TODO Auto-generated method stub

	}

	@Override
	public void load(SaveMgr saveMgr) {
		// TODO Auto-generated method stub

	}

	
	
}
